<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件


if (!function_exists('admin_aside_check')){
    function admin_aside_check($path){
        $request = \think\Request::instance();

        $pathArr = is_string($path) ? [$path] : $path;

        $currModule = $request->module();
        $currController = $request->controller();
        $currAction = $request->action();
        foreach ($pathArr as $v){
            // 单个匹配
            $pathItemArr = explode('/',$v);
            $pathItemArrCount = count($pathItemArr);
            switch ($pathItemArrCount){
                case 3:
                    if (strtolower($currModule) == strtolower($pathItemArr[0]) &&
                        strtolower($currController) == strtolower($pathItemArr[1]) &&
                        strtolower($currAction) == strtolower($pathItemArr[2])
                    ){
                        return 'active';
                    }
                    break;
                case 2:
                    if (strtolower($currModule) == strtolower($pathItemArr[0]) &&
                        strtolower($currController) == strtolower($pathItemArr[1])
                    ){
                        return 'active';
                    }
                    break;
                case 1:
                    if (strtolower($currController) == strtolower($pathItemArr[0])){
                        return 'active';
                    }
                    break;
            }

        }

        return '';
    }
}
